-- gui_checkbox.lua

gui_checkbox = class('gui_checkbox', gui_element)

function gui_checkbox:initialize()
	self.string = ""
	self.pos = {x = 0, y = 0}
	self.size = {w = 0, h = 0}
	self.panel_x = 0
	self.panel_y = 0
	self.checked = false
	self.hover = false
	self.name = "Checkbox"
	self.colour = {r = 0, g = 0, b = 0}
	self.graphics = {checked = nil, blank = nil, hover = nil}
end

function gui_checkbox:draw()
	if self.checked then
		love.graphics.draw(self.graphics.checked, self.pos.x + self.panel_x, self.pos.y + self.panel_y)
	else
		love.graphics.draw(self.graphics.blank, self.pos.x + self.panel_x, self.pos.y + self.panel_y)
	end
	
	if self.hover then
		love.graphics.draw(self.graphics.hover, self.pos.x + self.panel_x, self.pos.y + self.panel_y)
	end
end

function gui_checkbox:update(dt)
	self.size = {w = self.graphics.checked:getWidth(), h = self.graphics.checked:getHeight()}
	
	if CheckCollision(self.pos.x + self.panel_x, self.pos.y + self.panel_y, self.size.w, self.size.h, love.mouse.getX(), love.mouse.getY(), 1, 1) then
		self.hover = true
	else
		self.hover = false
	end
end

function gui_checkbox:mousereleased(x, y, button)
	if CheckCollision(self.pos.x + self.panel_x, self.pos.y + self.panel_y, self.size.w, self.size.h, love.mouse.getX(), love.mouse.getY(), 1, 1) then
		if button == "l" then
			if self.checked == true then
				self.checked = false
			else
				self.checked = true
			end
		end
	end
end